package threadlocal;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 描述：共用一个SimpleDateFormat，线程不安全
 */

public class ThreadLocalNormalUsage02 {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    public String date(int seconds) {
        // 参数的单位是毫秒，从1970.1.1 0:00:00 GMT计时 对于中国来说，要加上8个小时
        Date date = new Date(1000L * seconds);
        return dateFormat.format(date);
    }
    public static ExecutorService threadPool = Executors.newFixedThreadPool(10);
    public static void main(String[] args) {
        for (int i = 0; i < 1000; i++) {
            int finalI = i;
            threadPool.submit(() -> {
                String date = new ThreadLocalNormalUsage02().date(finalI);
                System.out.println(date);
            });
        }
        threadPool.shutdown();
    }
}
